package Editor;

import graphics.ComponentFrame;
import graphics.WorldDrawer;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

import physics.Coordinate;
import physics.ImmovableObstacle;
import physics.World;
import physics.shape.Circle;
import physics.shape.ObstaclePolygon;

public class WorldEditor  extends JPanel {
 
	
BufferedImage img;
World w;

	public WorldEditor(World w){
		this.w = w;
		setMinimumSize(new Dimension(800,800));
		setMaximumSize(new Dimension(1900,1080));
		setPreferredSize(ComponentFrame.getScreenSize());
		setSize(getPreferredSize());
		repaint();
		w.start();
	}


	public void paint(Graphics g){
		//img =(BufferedImage) createImage(this.getWidth(),this.getHeight());
		img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
		Graphics2D g2D = (Graphics2D) img.createGraphics();
		WorldDrawer.drawWorld(g2D, w);
		g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
	}
	
	public void update(Graphics g){
		paint(g);
	}
	
	
	public static void main(String args []){
		World w = new World();
		
	
		
		Circle circle = new Circle(new Coordinate(150,150), 20);
	Shape poly = new ObstaclePolygon();
		ImmovableObstacle obst = new ImmovableObstacle(new Coordinate(100,75), circle, 2);
		((Polygon) poly).addPoint(50, 50);
		((Polygon) poly).addPoint(100, 50);
		((Polygon) poly).addPoint(100, 100);
		((Polygon) poly).addPoint(50,100);
		
		w.addObstacle(obst);
		WorldEditor e = new WorldEditor(w);
		ComponentFrame.showFrame("test", e);
	}
}
